package com.duobaoyu.dby.supply.admin.service.impl;

import com.duobaoyu.dby.supply.admin.service.AdminOrderOperateLogBizService;
import com.duobaoyu.dby.supply.biz.service.config.OperationLogService;
import com.duobaoyu.dby.supply.common.biz.bo.config.OperationLogBO;
import com.duobaoyu.dby.supply.common.biz.dto.config.OperationLogListDTO;
import com.duobaoyu.dby.supply.common.biz.dto.log.OperateLogDTO;
import com.duobaoyu.dby.supply.common.biz.vo.log.OperateLogDetailVO;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 订单操作日志业务接口实现
 * @Author yangyong
 * @Date 2023/10/23
 */
@Service
@RequiredArgsConstructor
public class AdminOrderOperateLogBizServiceImpl implements AdminOrderOperateLogBizService{
	private final OperationLogService operationLogService;

	@Override
	public List<OperateLogDetailVO> listOperateLogDetail(OperateLogDTO orderOperateLog){
		OperationLogListDTO logQuery = new OperationLogListDTO();
		logQuery.setBizKey(orderOperateLog.getBizKey());
		logQuery.setLogType(orderOperateLog.getLogType());
		List<OperationLogBO> operationLogList = operationLogService.list(logQuery);
		if(CollectionUtils.isEmpty(operationLogList)){
			return Collections.emptyList();
		}
		return operationLogList.stream()
				.map(o -> OperateLogDetailVO
						.builder()
						.orderSn(o.getBizKey())
						.content(o.getContent())
						.source(o.getSource())
						.description(o.getScene())
						.operator(o.getOperator())
						.createTime(o.getCreateTime())
						.build())
				.collect(Collectors.toList());
	}
}
